layui.define(function (exports) {
  var $ = layui.$, laypage = layui.laypage, dropdown = layui.dropdown,form=layui.form;
  const mydelay=800;
  var url1,pLang;
  var obj = {

      setUrl: function (url){
        url1 = url;
      },
      getUrl: function(){
        return url1;
      },
      mydelay: function () {
        return mydelay;
      },
      menu1: function menu() {
        dropdown.render({
          elem: '#demo3'
          , data: [
            {
              title: 'C在线'
              , id: 1
            }, 
            {
              title: 'C++在线'
              , id: 5
            },             
            {
              title: 'JavaScript在线'
              , id: 2
            },
            {
              title: 'ASP在线'
              , id: 3
            },
            {
              title: 'PHP在线'
              , id: 4
            },
            {
              type: '-' //分割线
            }
            , {
              title: ' 场景6 C语言程序题自动判分'
              , id: 5484166
            }, {
              title: '场景1 美女程序员讲述 《上传文件》'
              , id: 5475187
            }, {
              type: '-' //分割线
            }/*, {
              title: '我与FoxPro'
              , id: 5436327
            }, {
              title: '我与FoxPro（番外篇） --他们眼中的我'
              , id: 5453994
            }*/]
          , click: function (obj) {
            this.elem.val(obj.title);
            var url = "http://124.222.154.144:8383/dzps/yx/";
            switch (obj.id) {
              case 1:
                url += "onc_1.asp";
                break;
              case 2:
                url += "onjs_1.asp";
                break;
              case 3:
                url += "onasp_1.asp";
                break;
              case 4:
                url += "onphp_1.asp";
                break;
              case 5:
                url += "oncpp_1.asp";
                break;
              default:
                url = "https://my.oschina.net/u/4196005/blog/" + obj.id;
            }
            ;
            window.location.href = url;
          }
        });
      }
      , list: function list(log1_id) {
        if (log1_id == '') {
        }
        else {
          $.post('pj.asp', { action: "code_list", log1_id1: log1_id },
            function (data) { $("#runr").val(data); });
        }
      }
      , msg0: function msg0(txt, seconds) {
        layer.open({
          type: 1
          , time: seconds * 1000
          , skin: 'layui-layer-molv'
          , content: '<div style="padding: 20px 20px;">' + txt + '</div>'
          , btn: '关闭'
          , btnAlign: 'c'
          , shade: 0
          , end: function () {
            layer.closeAll();
          }
        });
      }
      , txt_runr: function txt_runr(fname) {
        $.post('pj.asp', { action: "get_m_f", fname: fname },
          function (data) { $("#runr").val(data); });
      }
      , myload: function myload(logid) {
        let log1_id = $("#log1_id").val();
        switch (logid) {
          case 'c':
            logid = '851';// 851 默认选为示例代码，可修改
            break;
          case 'asp':
            logid = '864';
            break;
          case 'php':
            logid = '871';
            break;
          case 'cc':
            logid = '873';
            break;
        }

        log1_id = log1_id == '' ? logid : log1_id;
        $.post('pj.asp', { action: "log1_get", log1_id1: log1_id },
          function (data) {
            editor.setValue(data);
            $("#code_list").click();
          });
      }
      , code_del: function code_del() {
        $.post('pj.asp?now=' + new Date().getTime(), {
          action: "code_del"
        },
          function (data) {
            layer.msg(data);
          });
      }
      , msg0_b: function msg0_b(txt, seconds) {
        layer.open({
          type: 1
          , title: false
          , anim: 5
          , closeBtn: 0
          , offset: 'b'
          , time: seconds * 1000
          , skin: 'layui-layer-molv'
          , content: '<div style="padding: 25px 10px;">' + txt + '</div>'
          , btn: '关闭'
          , btnAlign: 'c' 
          , shade: 0 
          , end: function () {
            layer.closeAll();
          }
        });
      }
      , msg_p_runr_get0: function (txt) {
        layer.open({
          type: 1
          , time: mydelay*5
          , skin: 'layui-layer-molv'
          , content: '<div style="padding: 20px 10px;">' + txt + '</div>'
          , btn: '关闭'
          , btnAlign: 'c' //按钮居中
          , shade: 0 //不显示遮罩
          , end: function () {
            $("#runr_get0").click();
            layer.closeAll();
          }
        });
      }
      , l_data: function l_data(str) {
        url_gg = "&log1_search=" + $('#log1_search').val() + "&sd=" + $('#sd').val() + "&ed=" + $('#ed').val();
        $.ajax({
          url: "pj.asp?action=upf_1_count" + url_gg,
          success: function (res) {
            yj_count = Number(res);
            laypage.render({
              elem: 'test1'
              , count: yj_count
              , limit: str
              , jump: function (obj, first) {
                $.ajax({
                  url: 'pj.asp?action=upf_1_lst&page=' + obj.curr + url_gg,
                  success: function (res) {
                    if (obj.curr != 1) {
                      layer.msg('第 ' + obj.curr + ' 页');
                    }
                    $('dl.layuiadmin-card-status').html(res);
                    $('#page').val(obj.curr);
                  },
                  error: function (error) {
                    alert('数据加载失败');
                  }
                });
              }
            });
          },
          error: function (error) {
            alert('数据加载失败');
          }
        });
      }
    };
    $(document).keydown(function(e) {
      if (e.keyCode == 13 && e.ctrlKey) {
        $("#code_add").click();
      }
    });
    $.post('pj.asp', { action: "r_session", r_session: "opentime" },
    function (data) {
      if (data == "") {
        if ($("#log1_id").val() == "")
          mymod.msg0("月心编程小册子 <br><br>欢迎您！<br><br>月在上方诸品静，心持半偈万缘空<br><br>", 5);
      }
    });
    form.on('submit(code_del)',function(data) {obj.code_del();});
    form.on('submit(exam_m)',function(data) {window.location.href = "/dzps/src/views/xxk/log1_ml.asp?status="+$("#getpLang").val();});
    obj.txt_runr("runr.txt");
    obj.menu1();
    form.on('submit(code_list)',function(data) {
      if($("#log1_id").val() == ''){
        obj.msg0("当前为自由练习模式！请放飞您的思路写代码吧！",5);}
      else{
        $.post('pj.asp', {action: "code_list",log1_id1:$("#log1_id").val()},
        function(data) {
          obj.msg0_b(data,30);
        });         
      }
    });
    form.on('submit(free)',function(data) {
      if($("#log1_id").val() == ''){
        obj.msg0("当前是自由练习模式，请开心写代码！想做题，请点【选题】哦。",5);
      }
      else
        window.location.href = obj.getUrl();});

  exports('mymod', obj);
});